/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package parse_tree;

import java.util.ArrayList;

/**
 *
 * @author ravi
 */
public class Node {

    ArrayList<Node> childNodes;
    String readValue;
    String translatedValue;

    public Node(ArrayList<Node> childNodes, String readValue, String translatedValue) {
        this.childNodes = childNodes;
        this.readValue = readValue;
        this.translatedValue = translatedValue;
    }

    public Node(ArrayList<Node> childNodes, String readValue, Object translatedValue) {
        this.childNodes = childNodes;
        this.readValue = readValue;
        this.translatedValue = translatedValue.toString();
    }


    public Node(String translatedValue){
        this.translatedValue = translatedValue;
    }

    public Node(Object translatedValue){
        try{
            this.translatedValue = ((Node)translatedValue).getTranslatedValue();            
        }catch(ClassCastException ex){
            this.translatedValue = translatedValue.toString();            
        }        
    }

    public ArrayList<Node> getChildNodes() {
        return childNodes;
    }

    public Node getChildNodeByName(String name) {
        Node n = null;
        while (childNodes.iterator().hasNext()) {
            n = childNodes.iterator().next();
            if (n.readValue.equals(name)) {
                return n;
            }
        }
        return n;
    }

    public void setChildNodes(ArrayList<Node> childNodes) {
        this.childNodes = childNodes;
    }

    public String getReadValue() {
        return readValue;
    }

    public void setReadValue(String readValue) {
        this.readValue = readValue;
    }

    public String getTranslatedValue() {
        return translatedValue;
    }

    public void setTranslatedValue(String translatedValue) {
        this.translatedValue = translatedValue;
    }

    public static void main(String[] args) {
        Node n = new Node(new ArrayList<Node>(), "", "rest");
        System.out.println("readValue = " + n.getReadValue());
        System.out.println("testValue = " + n.getTranslatedValue());
    }
}
